package com.system.menu;

import com.system.service.CommentService;
import com.system.service.MainPageService;
import com.system.service.NotificationService;
import com.system.service.TopicsService;

import java.util.InputMismatchException;
import java.util.Scanner;

public class MainMenu {
    public final  Scanner sc ;
    private final MainPageService mps;
    private final TopicsService ts;
    private final CommentService cs;
    private final NotificationService ns;

    public MainMenu() {
        this.mps = new MainPageService();
        this.ts = new TopicsService();
        this.cs = new CommentService();
        this.ns = new NotificationService();
        this.sc = new Scanner(System.in);
    }

    // for user
    public void mainMenu(String email) {
        boolean flg = true;
        while (flg) {
            mps.initMainPageForUser(email);  // email 跳转那里拿
            System.out.println("请输入您的选择(1-4):");
            try {
                int opt = sc.nextInt();
                switch (opt) {
                    case 1:
                        ts.menu(email);
                        break;
                    case 2:
                        mps.addContentM(email);
                        break;
                    case 3:
                        cs.ShowAllTopicsMenu(email);
                        break;
                    case 4:
                        ns.notificationMenu(email);
                        break;
                    case 5:
                        boolean exit = continue_menu();
                        if (exit) {
                            flg = false;
                            break;
                        }
                        System.out.println("请重新选择：");
                        continue;
                    default:
                        System.out.println("输入错误—_—");

                }
            }catch(InputMismatchException e) {
                System.out.println("输入错误，请输入数字！");
                sc.next(); // 清除错误输入
            }
        }
    }

    public boolean continue_menu() {
        System.out.println("退出y/n");
        char ch = sc.next().charAt(0);  // 接受单个字符串
        if (ch == 'y' || ch == 'Y') {
            System.out.println("今天没有烦恼,希望明天的你也是！");
            return true;
        } else if (ch == 'n' || ch == 'N') {
            return false;
        }
        return false;  // 待完善 输出y以为的其他字符都退出
    }

}
